using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Build.Utilities;
using System.IO;
using Microsoft.Build.Framework;

namespace BizTalk.BuildGenerator.Tasks.BRE
{
    /// <summary>
    /// Task to remove a policy, if the version is supplied then it will remove the specific version
    /// if not then all versions will be removed
    /// </summary>
    public class RemovePolicy : BaseBRETask
    {
        private string _PolicyName;

        /// <summary>
        /// The name of the policy
        /// </summary>
        [Required]
        public string PolicyName
        {
            get { return _PolicyName; }
            set { _PolicyName = value; }
        }

        /// <summary>
        /// Task execute method
        /// </summary>
        /// <returns></returns>
        public override bool Execute()
        {
            BREManager mgr = base.CreateManager();
            if (this.MajorVersion >= 0 && this.MinorVersion >= 0)
            {
                this.Log.LogMessage("Remove specific policy", null);
                mgr.Remove(RulesEngineObjectType.RuleSetInfo, this._PolicyName, this.MajorVersion, this.MinorVersion);
            }
            else
            {
                this.Log.LogMessage("Remove all versions of policy", null);
                mgr.Remove(RulesEngineObjectType.RuleSetInfo, this._PolicyName);
            }
            return true;
        }
    }
}
